package top.hkyzf.study.leetcode.string;

import org.junit.Test;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * description:
 *
 * @author zhufeng
 * @version 1.0
 * @date 2024-3-16 22:59
 */
public class 替换字符串中的问号使分数最小_100249 {
    /**
     * 未完成
     * @param s
     * @return
     */
    public String minimizeStringValue(String s) {
        Set<Character> set = new HashSet<>();
        char[] chars = s.toCharArray();
        int count = 0;
        for (char aChar : chars) {
            if (aChar != '?') {
                set.add(aChar);
            } else {
                count++;
            }
        }
        int next = 97;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '?') {
                while (next < 122) {
                    if (!set.contains((char) next)) {
                        chars[i] = (char) next;
                        set.add((char) next);
                        count--;
                        break;
                    } else {
                        next = next + 1;
                    }
                }
                if (next >= 122) {
                    if (count == 1) {
                        chars[i] = 'z';
                    } else {
                        chars[i] = 'a';
                        count--;
                    }
                }
            }
        }
        return new String(chars);
    }

    /**
     * 未完成
     */
    @Test
    public void testMinimize () {
        String s = "??k?l??gtqxj?rtneyxku?o?q?w?aba";
        s = "abcdefghijklmnopqrstuvwxy??";
        s = "g?xvgroui??xk?zqb?da?jan?cdhtksme";
        System.out.println(minimizeStringValue(s));
    }
}
